﻿using WikiMaml.Renderers;
using Xunit;
using Xunit.Extensions;

namespace WikiMaml.Facts.Renderers
{
    public class ContainerRendererFacts
    {
        public class CanExpand
        {
            [Theory]
            [InlineData(MamlScopeName.IntroductionBegin)]
            [InlineData(MamlScopeName.IntroductionWithOutlineBegin)]
            [InlineData(MamlScopeName.IntroductionEnd)]
            [InlineData(MamlScopeName.Markup)]
            [InlineData(MamlScopeName.ParagraphBegin)]
            [InlineData(MamlScopeName.ParagraphEnd)]
            [InlineData(MamlScopeName.ProcedureBegin)]
            [InlineData(MamlScopeName.ProcedureEnd)]
            [InlineData(MamlScopeName.SectionBegin)]
            [InlineData(MamlScopeName.SectionEnd)]
            [InlineData(MamlScopeName.StepBegin)]
            [InlineData(MamlScopeName.StepEnd)]
            public void Should_be_able_to_expand_scope_name(string scopeName)
            {
                var renderer = new ContainerRenderer();

                bool result = renderer.CanExpand(scopeName);

                Assert.True(result);
            }
        }

        public class Expand
        {
            [Theory]
            [InlineData(MamlScopeName.IntroductionBegin, "<introduction>")]
            [InlineData(MamlScopeName.IntroductionWithOutlineBegin, "<introduction><autoOutline />")]
            [InlineData(MamlScopeName.IntroductionEnd, "</introduction>")]
            [InlineData(MamlScopeName.SectionEnd, "</content></section>")]
            [InlineData(MamlScopeName.ParagraphBegin, "<para>")]
            [InlineData(MamlScopeName.ParagraphEnd, "</para>")]
            [InlineData(MamlScopeName.StepBegin, "<step><content>")]
            [InlineData(MamlScopeName.StepEnd, "</content></step>")]
            public void Should_expand_the_scope_correctly(string scopeName, string expectedResult)
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(scopeName, string.Empty, x => x, x => x);

                Assert.Equal(expectedResult, actualResult);
            }

            [Fact]
            public void Should_expand_the_section_begin_correctly()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.SectionBegin, "the title", x => x, x => x);

                Assert.Equal("<section><title>the title</title><content>", actualResult);
            }

            [Fact]
            public void Should_html_encode_the_section_title()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.SectionBegin, "the title", x => "encoded", x => x);

                Assert.Equal("<section><title>encoded</title><content>", actualResult);
            }

            [Fact]
            public void Should_expand_the_markup_correctly()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.Markup, "<b>foo</b>", x => x, x => x);

                Assert.Equal("<markup><b>foo</b></markup>", actualResult);
            }

            [Fact]
            public void Should_not_html_encode_the_markup()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.Markup, "<b>foo</b>", x => "foo", x => x);

                Assert.Equal("<markup><b>foo</b></markup>", actualResult);
            }

            [Fact]
            public void Should_render_procedure_begin_markup_correctly()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.ProcedureBegin, "title", x => x, x => x);

                Assert.Equal("<procedure><title>title</title><steps class=\"ordered\">", actualResult);
            }

            [Fact]
            public void Should_html_encode_procedure_title()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.ProcedureBegin, "title", x => "foo", x => x);

                Assert.Equal("<procedure><title>foo</title><steps class=\"ordered\">", actualResult);
            }

            [Fact]
            public void Should_render_procedure_end_markup_correctly()
            {
                var renderer = new ContainerRenderer();

                string actualResult = renderer.Expand(MamlScopeName.ProcedureEnd, "{procedure}", x => x, x => x);

                Assert.Equal("</steps></procedure>", actualResult);
            }
        }
    }
}
